package net.zoneland.knowledge.dao;

import java.util.List;
import net.zoneland.knowledge.model.Favorite;
import net.zoneland.knowledge.model.FavoriteExample;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;

@Mapper
public interface FavoriteMapper {
    @SelectProvider(type=FavoriteSqlProvider.class, method="countByExample")
    long countByExample(FavoriteExample example);

    @Delete({
        "delete from AITK_FAVORITE",
        "where ID = #{id,jdbcType=VARCHAR}"
    })
    int deleteByPrimaryKey(String id);

    @Insert({
        "insert into AITK_FAVORITE (ID, ES_QUESTION_ID, ",
        "CREATOR_UID, CREATOR_NAME, ",
        "CREATE_TIME, UPDATE_TIME, ",
        "ENABLED, CATEGORY, TITLE_TYPE)",
        "values (#{id,jdbcType=VARCHAR}, #{esQuestionId,jdbcType=VARCHAR}, ",
        "#{creatorUid,jdbcType=VARCHAR}, #{creatorName,jdbcType=VARCHAR}, ",
        "#{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP}, ",
        "#{enabled,jdbcType=DECIMAL}, #{category,jdbcType=VARCHAR}, #{titleType,jdbcType=VARCHAR})"
    })
    int insert(Favorite record);

    @InsertProvider(type=FavoriteSqlProvider.class, method="insertSelective")
    int insertSelective(Favorite record);

    @SelectProvider(type=FavoriteSqlProvider.class, method="selectByExample")
    @Results({
        @Result(column="ID", property="id", jdbcType=JdbcType.VARCHAR, id=true),
        @Result(column="ES_QUESTION_ID", property="esQuestionId", jdbcType=JdbcType.VARCHAR),
        @Result(column="CREATOR_UID", property="creatorUid", jdbcType=JdbcType.VARCHAR),
        @Result(column="CREATOR_NAME", property="creatorName", jdbcType=JdbcType.VARCHAR),
        @Result(column="CREATE_TIME", property="createTime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="UPDATE_TIME", property="updateTime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="ENABLED", property="enabled", jdbcType=JdbcType.DECIMAL),
        @Result(column="CATEGORY", property="category", jdbcType=JdbcType.VARCHAR),
        @Result(column="TITLE_TYPE", property="titleType", jdbcType=JdbcType.VARCHAR)
    })
    List<Favorite> selectByExample(FavoriteExample example);

    @Select({
        "select",
        "ID, ES_QUESTION_ID, CREATOR_UID, CREATOR_NAME, CREATE_TIME, UPDATE_TIME, ENABLED, ",
        "CATEGORY",
        "from AITK_FAVORITE",
        "where ID = #{id,jdbcType=VARCHAR}"
    })
    @Results({
        @Result(column="ID", property="id", jdbcType=JdbcType.VARCHAR, id=true),
        @Result(column="ES_QUESTION_ID", property="esQuestionId", jdbcType=JdbcType.VARCHAR),
        @Result(column="CREATOR_UID", property="creatorUid", jdbcType=JdbcType.VARCHAR),
        @Result(column="CREATOR_NAME", property="creatorName", jdbcType=JdbcType.VARCHAR),
        @Result(column="CREATE_TIME", property="createTime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="UPDATE_TIME", property="updateTime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="ENABLED", property="enabled", jdbcType=JdbcType.DECIMAL),
        @Result(column="CATEGORY", property="category", jdbcType=JdbcType.VARCHAR)
    })
    Favorite selectByPrimaryKey(String id);

    @UpdateProvider(type=FavoriteSqlProvider.class, method="updateByExampleSelective")
    int updateByExampleSelective(@Param("record") Favorite record, @Param("example") FavoriteExample example);

    @UpdateProvider(type=FavoriteSqlProvider.class, method="updateByExample")
    int updateByExample(@Param("record") Favorite record, @Param("example") FavoriteExample example);

    @UpdateProvider(type=FavoriteSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(Favorite record);

    @Update({
        "update AITK_FAVORITE",
        "set ES_QUESTION_ID = #{esQuestionId,jdbcType=VARCHAR},",
          "CREATOR_UID = #{creatorUid,jdbcType=VARCHAR},",
          "CREATOR_NAME = #{creatorName,jdbcType=VARCHAR},",
          "CREATE_TIME = #{createTime,jdbcType=TIMESTAMP},",
          "UPDATE_TIME = #{updateTime,jdbcType=TIMESTAMP},",
          "ENABLED = #{enabled,jdbcType=DECIMAL},",
          "CATEGORY = #{category,jdbcType=VARCHAR},",
          "TITLE_TYPE = #{titleType,jdbcType=VARCHAR}",
        "where ID = #{id,jdbcType=VARCHAR}"
    })
    int updateByPrimaryKey(Favorite record);

    @Select({
            "select",
            "ID, ES_QUESTION_ID, CREATOR_UID, CREATOR_NAME, CREATE_TIME, UPDATE_TIME, ENABLED, ",
            "CATEGORY, TITLE_TYPE",
            "from AITK_FAVORITE",
            "where CREATOR_UID = #{userId,jdbcType=VARCHAR} AND ENABLED = 1"
    })
    @Results({
            @Result(column="ID", property="id", jdbcType=JdbcType.VARCHAR, id=true),
            @Result(column="ES_QUESTION_ID", property="esQuestionId", jdbcType=JdbcType.VARCHAR),
            @Result(column="CREATOR_UID", property="creatorUid", jdbcType=JdbcType.VARCHAR),
            @Result(column="CREATOR_NAME", property="creatorName", jdbcType=JdbcType.VARCHAR),
            @Result(column="CREATE_TIME", property="createTime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="UPDATE_TIME", property="updateTime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="ENABLED", property="enabled", jdbcType=JdbcType.DECIMAL),
            @Result(column="CATEGORY", property="category", jdbcType=JdbcType.VARCHAR),
            @Result(column="TITLE_TYPE", property="titleType", jdbcType=JdbcType.VARCHAR)
    })
    List<Favorite> selectByCreatorUid(String userId);
}
